package y2015.date0917am.mysql连接1;

import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Connection_Mysql {


    @Test
    public void main() throws Exception {
        Statement stmt;
        Connection conn;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("注册jar包的驱动类文件->>完成");
            //连接到mysql数据库
            String host = "127.0.0.1";
            String port = "3306";
            String database = "test";
            //				jdbc:mysql://127.0.0.0:3306/tarena_chat
            String url = "jdbc:mysql://" + host + ":" + port + "/" + database;
            String user = "root";
            String password = "root";

            //				管理一组 JDBC 驱动程序的基本服务。
            try {
                conn = DriverManager.getConnection(url, user, password);
                System.out.println(conn.getMetaData().getDatabaseProductVersion());
                stmt = conn.createStatement();
                System.err.println("test 数据库最大行数" + stmt.getMaxRows());
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

}

